﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics.Contracts;

using SimpleIR;
using RgnAnalyzer.Domain;

namespace RgnAnalyzer
{
	/// <summary>
	/// Represent the possible match states with a currently memoized <c>MethodContextState</c>.
	/// </summary>
	internal enum MatchCase { EqualityMatch, SubsumeMatch, SubsumeAlter, FreshMatch };

	///<summary> 
	/// A helper class to group arg passing: given g_arg, memo (gin, gout) want g_res.
	///</summary>
	internal sealed class CallStateSubMap
	{
		/// <summary>
		/// Report the resuling match status for the memoized analysis state.
		/// </summary>
		internal MatchCase OutCase;

		/// <summary>
		/// A map from identity tags in the memoized versions (gin gout) to the identity tags in g_arg and that we want to prop to g_res.
		/// </summary>
		internal readonly Dictionary<int, HashSet<int>> ResMap;

		/// <summary>
		/// A map from external ref names in the memoized versions (gin gout) to the external refs in g_arg and that we want to prop to g_res.
		/// </summary>
		internal readonly Dictionary<AExternalRef, HashSet<AExternalRef>> ExtRefMap;

		[ContractInvariantMethod]
		private void ObjectInvariant()
		{
			Contract.Invariant(this.ResMap != null);
			Contract.Invariant(this.ExtRefMap != null);
		}

		internal CallStateSubMap()
		{
			this.OutCase = MatchCase.FreshMatch;

			this.ResMap = new Dictionary<int, HashSet<int>>();
			this.ExtRefMap = new Dictionary<AExternalRef, HashSet<AExternalRef>>();
		}
	}
}
